package com.j180.dao.service;

import com.j180.bean.Service;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IServiceDao {

    @Select("SELECT\n" +
            "            se.se_id as seId,\n" +
            "            se.se_name as seName,\n" +
            "            se.se_type as seType,\n" +
            "            se.se_schedule as seSchedule,\n" +
            "            se.se_applicable as seApplicable,\n" +
            "            se.se_serviceSpec as seServiceSpec,\n" +
            "            se.se_spendTime as seSpendTime,\n" +
            "            se.se_clerkLevel as seClerkLevel,\n" +
            "            se.se_price as sePrice,\n" +
            "            st.st_id as stId,\n" +
            "            st.st_name as stName \n" +
            "        FROM\n" +
            "            t_store AS st \n" +
            "                left JOIN t_service AS se ON se.se_st_id = st.st_id\n" +
            "        WHERE st.st_id=#{stId}")
    @ResultMap("serviceResult.getService")
    List<Service> listByStId(@Param("stId") int stId);


    /**
     * 管理员根据门店id服务id查询某一服务
     *
     * @param id Integer类型，门店id
     * @return Service类，服务信息
     */

    @Select("SELECT\n" +
            "            se.se_id as seId,\n" +
            "            se.se_name as seName,\n" +
            "            se.se_type as seType,\n" +
            "            se.se_schedule as seSchedule,\n" +
            "            se.se_applicable as seApplicable,\n" +
            "            se.se_serviceSpec as seServiceSpec,\n" +
            "            se.se_spendTime as seSpendTime,\n" +
            "            se.se_clerkLevel as seClerkLevel,\n" +
            "            se.se_price as sePrice,\n" +
            "            st.st_id as stId,\n" +
            "            st.st_name as stName,\n" +
            "            st.st_licenseNum as stLicenseNum,\n" +
            "            st.st_licensePic as stLicensePic,\n" +
            "            st.st_address as stAddress,\n" +
            "            st.st_location as stLocation,\n" +
            "            st.st_city as stCity,\n" +
            "            st.st_corporation as stCorporation,\n" +
            "            st.st_telNum as stTelNum,\n" +
            "            st.st_photo as stPhoto,\n" +
            "            st.st_feature as stFeature,\n" +
            "            st.st_vipLevel as stVipLevel,\n" +
            "            st.st_commissionRate as stCommissionRate,\n" +
            "            st.st_clerkAttri as stClerkAttri  \n" +
            "        FROM\n" +
            "            t_store AS st\n" +
            "                left JOIN t_service AS se ON se.se_st_id = st.st_id\n" +
            "        WHERE st.st_id=#{id} and se.se_id= #{storeId}"
    )
   @ResultMap("serviceResult.ServiceMap")
   Service getStoreServicesById(@Param("id") int id,@Param("storeId") int storeId);

    /**
     * 管理员审批通过后添加一个服务信息
     *
     * @param service Service类类型，供货商
     * @return int类型，1表示添加成功
     */
    @Insert("INSERT INTO t_service VALUES (" +
            "null," +
            "#{name}," +
            "#{type}," +
            "#{schedule}," +
            "#{applicable}," +
            "#{serviceSpec}," +
            "#{spendTime}," +
            "#{clerkLevel}," +
            "#{price}," +
            "#{store.id})")
    int insertService(Service service);

    /**
     * 管理员根据id删除一个服务信息
     *
     * @param id Integer类型，供货商id
     * @return int类型，1表示删除成功
     */
    @Delete("delete from t_service where se_id = #{id}")
    int deleteService(@Param("id") int id);

    /**
     * 管理员修改服务信息
     *
     * @param service Service类型，服务信息
     * @return int类型，1表示修改成功
     */
    @Update("update t_service set " +
            "se_id = #{id}, " +
            "se_name = #{name}, " +
            "se_type = #{type}, " +
            "se_schedule = #{schedule}," +
            "se_applicable = #{applicable}, " +
            "se_serviceSpec = #{serviceSpec}," +
            "se_spendTime = #{spendTime}," +
            "se_clerkLevel = #{clerkLevel}," +
            "se_price = #{price}, " +
            "se_st_id = #{store.id}"+
            " where se_id = #{id}")
    int updateService(Service service);


}
